package tgc.edu.tgq.demo.web.controller;

import java.util.List;


import javax.persistence.GeneratedValue;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import tgc.edu.tgq.demo.entity.Course;
import tgc.edu.tgq.demo.entity.Grade;
import tgc.edu.tgq.demo.entity.Student;
import tgc.edu.tgq.demo.entity.SysUser;
import tgc.edu.tgq.demo.entity.TbClass;
import tgc.edu.tgq.demo.security.UserUtils;
import tgc.edu.tgq.demo.service.GradeService;
import tgc.edu.tgq.demo.service.StudentService;
import tgc.edu.tgq.demo.service.TbClassService;

@Controller
@RequestMapping(value = "/grade")
public class GradeController {
	@Autowired
	private GradeService gradeService;	
	@Autowired
	private UserUtils userUtils;
	@Autowired
	private StudentService studentService;
	@Autowired
	private TbClassService tbClassService;
	//----------个人成绩查询------------------
	@RequestMapping(value = "/personGrade")
	public String personGrade(ModelMap modelMap) {
		SysUser user=userUtils.getUser();
		Integer id=user.getId();
		List<Grade> list=gradeService.findByStudentId(id);
		modelMap.put("list",list);
		return "grade/personGrade";
	}
	//-------------通过id查找学生---------------
	@RequestMapping(value = "/classGrade")
	public String classGrade(ModelMap modelMap) {
		SysUser user=userUtils.getUser();
		Integer id=user.getId();
		Student student=studentService.findById(id);
		modelMap.put("stu", student);
		return "grade/classGrade";
	}
	
	//-----------班级成绩查询-------------------
	@RequestMapping(value = "/allStudentGrade")
	public String list(ModelMap modelMap) {
		List<TbClass> tbClass=tbClassService.findAll();
		modelMap.put("list",tbClass);
		return "grade/allStudentGrade";
	}
	
	//---------成绩表单----------
	@RequestMapping(value = "/bjChange")
	public String bjChange(Integer bjId,ModelMap modelMap) {
		List<Course> courses=gradeService.findCourseByTbClassId(bjId);
		List<List<Object>> list=gradeService.findAllGradeByTbClassId(courses, bjId);
		modelMap.put("kcs", courses);
		modelMap.put("cjb", list);
		return "grade/table";
	}
	
	//--------学生查询班级成绩----------
	@RequestMapping(value = "gradetable")
	public String gradetable(ModelMap modelMap) {
		SysUser user=userUtils.getUser();
		Integer id=user.getId();
		Student student=studentService.findById(id);
		Integer bjId=student.getTbClass().getId();
		List<Course> courses=gradeService.findCourseByTbClassId(bjId);
		List<List<Object>> list=gradeService.findAllGradeByTbClassId(courses, bjId);
		modelMap.put("kcs",courses);
		modelMap.put("cjb", list);
		return "grade/gradetable";
	}
}
